<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="com.bean.Article" %>
<%@ page import="com.bean.Comment" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
  request.setCharacterEncoding("UTF-8");
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<jsp:useBean id="categoryDao" class="com.daoImpl.CategoryDAOImpl"></jsp:useBean>
<jsp:useBean id="articleDao" class="com.daoImpl.ArticleDAOImpl"></jsp:useBean>
<jsp:useBean id="collectDao" class="com.daoImpl.CollectDAOImpl"></jsp:useBean>
<jsp:useBean id="commentDao" class="com.daoImpl.CommentDAOImpl"></jsp:useBean>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>摆烂俱乐部</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Google fonts - Roboto -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700">
    <!-- owl carousel-->
    <link rel="stylesheet" href="vendor/owl.carousel/assets/owl.carousel.css">
    <link rel="stylesheet" href="vendor/owl.carousel/assets/owl.theme.default.css">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
      <!-- Favicon-->
      <link rel="shortcut icon" href="favicon.png">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
  </head>
  <body>

  <%String username = (String) session.getAttribute("username");
    Object userid = session.getAttribute("userid");
  %>
    <!-- navbar-->
    <header class="header mb-5">
      <!--
      *** TOPBAR ***
      _________________________________________________________
      -->
      <jsp:include page="common/login.jsp"></jsp:include>
        <jsp:include page="common/top2.jsp"></jsp:include>
  <!-- 搜索 -->
      <jsp:include page="common/search.jsp"></jsp:include>
    </header>
<!-- *** TOP BAR END ***-->

    <div id="all">
      <div id="content">
        <div class="container">
          <div class="row">
           <div class="col-lg-12">
               <nav aria-label="breadcrumb">
                   <ol class="breadcrumb">
                       <li class="breadcrumb-item"><a href="index.jsp">家</a></li>
                       <li aria-current="page" class="breadcrumb-item active">文章详情</li>
                   </ol>
               </nav>
            
<%--        <%--%>
<%--          CommodityDaoImpl commodityDao=new CommodityDaoImpl();--%>
<%--          Commodity commodity = commodityDao.findCommodityById(Integer.parseInt(request.getParameter("id")));--%>
<%--          if(commodity!=null){--%>
<%--        %>--%>
            <%
              String article_id = "";
              if (request.getParameter("article_id") != null){
                article_id = request.getParameter("article_id");
                Article articleDetail = articleDao.getArticleById(article_id);
                request.setAttribute("articleDetail", articleDetail);
              }
            %>
            
            <div class="col-lg-12 order-1 order-lg-2">
              <div id="productMain" class="row">
                <div class="col-md-4">
                  <img src="upload/article/${articleDetail.article_cover}" alt="文章封面" class="img-fluid">
                  <div class="ribbon sale" style="opacity: 0.9;">
                    <div class="theribbon">${articleDetail.username}</div>
                    <div class="ribbon-background"></div>
                  </div>
                  <!-- /.ribbon-->
                  <div class="ribbon new" style="opacity: 0.9;">
                    <div class="theribbon">摆烂</div>
                    <div class="ribbon-background"></div>
                  </div>
                  <!-- /.ribbon-->
                </div>
                <div class="col-md-8">
                  <div class="box">
                    <h1 class="text-center">${articleDetail.article_title}</h1>
                    <p class="goToDescription"><a href="#details" class="scroll-to">滚动至评论</a></p>
                    <p class="text">文章作者：${articleDetail.username}</p>
                    <p class="text">文章分类：${articleDetail.category_name}</p>
                    <p class="text">发表时间：${articleDetail.create_time}</p>
                    <p class="text">修改时间：${articleDetail.update_time}</p>
                    <p class="price">文章内容</p>
                    <text class="text">${articleDetail.content}</text>

<!-- 收藏文章 -->
			  <%if(session.getAttribute("username")==null){%>	
                <p class="text-center buttons"><a href="register.jsp" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> 收藏文章</a></p>
              <%}
              else{ %>
                      <% if (collectDao.sCollectArticle(session.getAttribute("userid"), article_id)){%>
                      <form method="post" action="./article?action=noCollect">
                        <input type="hidden" value="<%=session.getAttribute("userid")%>" name="userid">
                        <input type="hidden" value="${articleDetail.article_id}" name="article_id">
                        <p class="text-center">
                            <button type="submit" name="submit" class="btn btn-primary"><i class="fa fa-shopping-cart" ></i> 取消收藏</button>
                            <a href="fileDownloadServlet?name=${articleDetail.article_cover}" class="btn btn-primary">下载文章封面</a>
                        </p>
                      </form>
                      <%}
                      else{ %>
                        <form method="post" action="./article?action=collect">
                          <input type="hidden" value="<%=session.getAttribute("userid")%>" name="userid">
                          <input type="hidden" value="${articleDetail.article_id}" name="article_id">
                        <p class="text-center"><button type="submit" name="submit" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> 收藏文章</button></p>
                        </form>
                      <%}%>
<%--                <p class="text-center buttons"><a href="#" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> 收藏文章</a></p>--%>
              <%}%>

                  </div>
                </div>
              </div>
                <%
                    List<Comment> comments = commentDao.getComments(article_id);
                    request.setAttribute("comments",comments);
                %>
              <div id="details" class="box">
                <h4 class="text-center">评论</h4>
                <form method="post" action="./comment?action=getAllById">
                  <div class="row">
                      <input type="hidden" name="userid" value="<%=userid%>">
                      <input type="hidden" name="article_id" value="${articleDetail.article_id}">
                      <textarea name="content" class="col-md-8 form-control custom-textarea" style="margin-left: 50px"></textarea>
                      <%if(session.getAttribute("username")==null){%>
                        <button formaction="register.jsp" type="submit" name="submit" class="col-md-1 btn btn-primary" style="height: 50%;margin-left: 20px;margin-top: 20px;">发布</button>
                      <%}else {%>
                        <button type="submit" name="submit" class="col-md-1 btn btn-primary" style="height: 50%;margin-left: 20px;margin-top: 20px;">发布</button>
                      <%}%>
                  </div>
                </form>
                  <div class="container" style="margin-top: 20px;">
                      <c:forEach items="${comments}" var="item">
                      <div class="card">
                          <div class="card-body">
                              <div class="card-header d-flex justify-content-between">
                                  <span>${item.username}</span>
                                  <span>发布时间：${item.create_time}</span>
                              </div>
                              <div class="card-body">
                                  <p>${item.content}</p>
                              </div>
                          </div>
                      </div>
                      </c:forEach>
                  </div>
                <hr>
              </div>
            </div>
            <!-- /.col-md-9-->
          </div>
        </div>
      </div>
    </div>
<!--
    *** 版权 ***
    _________________________________________________________
    -->
  <jsp:include page="common/copyright.jsp"></jsp:include>
<!-- *** COPYRIGHT END ***-->
    <!-- JavaScript files-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
    <script src="vendor/owl.carousel/owl.carousel.min.js"></script>
    <script src="vendor/owl.carousel2.thumbs/owl.carousel2.thumbs.js"></script>
    <script src="js/front.js"></script>
  </body>
</html>